package com.tonghe.controller;

import com.tonghe.annotation.SystemLog;
import com.tonghe.domain.ResponseResult;
import com.tonghe.domain.entity.User;
import com.tonghe.enums.AppHttpCodeEnum;
import com.tonghe.exception.SystemException;
import com.tonghe.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date:2022/2/20- 02- 20- 21:40
 * @author: tonghe
 **/
@RestController
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;

    /**
    * @description:登陆
    * @param： [user]
    * @return： com.tonghe.domain.ResponseResult
    */
    @SystemLog(businessName = "用户登陆")
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){

        if(!StringUtils.hasText(user.getUserName())){
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }

    /**
     * @description:退出登陆
     * @param： []
     * @return： com.tonghe.domain.ResponseResult
     */
    @SystemLog(businessName = "用户退出登陆")
    @PostMapping("/logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }

}
